class AgeError(Exception) :
    def __init__(self,error_info) -> None:
        self.error_info = error_info
    def __str__(self) -> str:
        return self.error_info
age = int(input("请输入年龄:"))
if age < 18 or age > 200 :
    raise AgeError("年龄不在正常人范围")
else :
    print(age)

"""""
使用try,except异常显示
"""
class AgeError(Exception) :
    def __init__(self,error_info) -> None:
        self.error_info = error_info
    def __str__(self) -> str:
        return self.error_info
age = int(input("请输入年龄:"))
try :
    if age < 18 or age > 200 :
        raise AgeError("年龄不在正常人范围")
    else :
        print(age)
except AgeError as a :
    print(a.error_info)